<?php

/*
create or replace view vpruebajornada
as
select r.id AS id, r.hora as hora,c.id as idcategoria, c.nombre AS categoria,j.id AS idjornada,j.nombre AS jornada,p.nombre AS prueba
from (((atletismo.rpruebajornada r join atletismo.categoria c) 
       join atletismo.jornada j) 
       join atletismo.catprueba p) 
where ((r.idcategoria = c.id) and (r.idjornada = j.id) and (r.idprueba = p.id))
order by hora,categoria;
*/

include_once('../includes/funciones_consulta.php');
session_start();

$jornadaid=$_REQUEST['id'];
$jornada = select("select * from jornada", "id=" . $jornadaid);

$competicionid=$jornada[0]['idcompeticion'];
$competicion =  select("select * from competicion", "id=" . $competicionid);


$temporadaid = $competicion[0]['idtemporada'];
$temporada =  select("select * from temporada", "id=" . $temporadaid);

$filtrocat="";
if (isset($_REQUEST['idcategoria']) && ($_REQUEST['idcategoria']!=0))
    $filtrocat = " and idcategoria=" . $_REQUEST['idcategoria'];

//print_r($competicion);
print "<h1>" . $temporada[0]['nombre'] ."</h1>";
print "<h2>" . $competicion[0]['nombre']  ."</h2>";
print "<h3>" . $jornada[0]['nombre'] . " " . $jornada[0]['fecha'] ."</h3>";

$sql = "select id,hora,prueba,categoria from vpruebajornada where idjornada=" . $jornadaid. $filtrocat;
$vpruebajornada = select2($sql .  " order by hora");

$actual = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];


print $sql;

 //print "<h3> Horario </h3>";
 //toHTML('vrpruebajornada',$vpruebajornada,'id');
 $html=horarioJornada('vrpruebajornada',$vpruebajornada,'id');
 foreach ($html as $linea) {
     print $linea;
 }
 
 
 $sql = "select distinct idcategoria,categoria from vpruebajornada where idjornada=" . $jornadaid;
 
 $cat = select2($sql);
 print "<form name=categoria action=verHorarioJornada.php method=post>";
 print "<input type=hidden name=id value='" . $jornadaid . "'>";
 print "<select name=idcategoria>";
 print "Categoria <option value='0'>--Todas--</option>";
 foreach ($cat as $fila){
     //print_r($cat);
     print "<option value='" . $fila['idcategoria'] . "'>" . $fila['categoria'] . "</option>";
 }
 print "<input type=submit value=aceptar>";
 print "</select>";
print "</form>";
  
  
 ?>


